Decompose Compound Wall

Dears,
I was able to decompose one compound wall into its layers.
But, when I have multiple walls, the script is not working properly,
I can not figure out the problem
your help is appreciated
DecomposeWall.dyn (89.0 KB)

One wall

Multiwall