Progressive alignment of Walls with Dynamo

Hello dear professionals,
Could you please give an idea about the script that can Align lines one by one sequentially.
Lets say I have a chain of walls in revit and they are not orthogonal. I need to have them so.
I don’t know what nodes I can use in order to make script to align walls in the next way.
from the ordered list take the first line, align it with X axis, after take second line from the ordered list, move the closest point to closest point of the first line (in order to maintain the chain of walls) and again align second line with X axis and so on

Please advise