Deformation in loft-How to fix it?

Hello all!

I try to create a curve based rail for a path but I cannot handle the loft of my curves with the right way. As a result, the lofted surface which created by loft command has a deformation at some points where the basic curve changes its direction. So it causes problems with my geometry. I would appreciate if you could have a look at my script and maybe help on how to fix the lofting process if you have a better idea.

Problem in (28.1 KB)

Thank you in advance!