Joining parallel walls by distance

Hello Dynamo experts,

I have made a script with help from some tutorial. The script is supposed to find the walls and create lines 500 mm on both sides of the walls and join the elements the line is intersecting with.

My problem is that the script is only joining 2 walls with eachother instead of all of them. The joined walls on the picture below are creating the voids caused by the windows placed on the walls. the outer wall seems to not join by running the script.

JoiningElementsByLine.dyn (58.4 KB)

Edit: The script seems to only join two walls and leave the third one out, eventhough the script seems to get the lines on those walls.
JoiningElementsByLine.dyn (62.8 KB)