Join intersecting surfaces

I have a Dynamo file that takes the 2 main surfaces of a wall (both sides) and then compares that to the surfaces of floors to find if there is any common surface between them using geomtery.intersect. This all works fine.

The thing I’m have trouble with is that if 2 or more of these surfaces intersect with each other I want to join them, if they do not intersect I want to leave the surface as is. In the below example there’s 3 surfaces I’d want joined to 2 but it could be any number of surfaces joined into any other amount.

dyn attached below


Wall to Floor Surface.dyn (17.9 KB)

I’ve managed to join the surfaces that intersect by grouping the intersecting surfaces then joining them using the polysurface node. That’s all great but there’s obviously duplicate polysurfaces that I’m struggling to remove