Issue with lofting direction

Hi all!
I have some contours that come as points. I import these points in GH and I partition them by the number of points in each ring. Based on these partitions, I interpolate curves. So I end up with a number of curves. My final goal is to loft or sweep through these curves and get a surface. The issues:
i) Sometimes the number of points that I partition is not accurate (+,- 1). I currently fix that by closing each open curve, so this is fine, or at least not something that worries me right now.
ii) When lofting, I get weird twists in between a couple or more ‘rings’ (or none sometimes). I have checked a lot of things such as aligning the seam (through a component called AliCrvAliSeam, I believe from pufferfish addon) or from some scripts that I have found online. Sometimes this has worked and some other not. I have also checked that the curves are ordered. I don’t know what I am missing anymore. When not having aligned seams, I end up with ‘waters’ imprinted on the loft that follow the path of the seams, so I get that.
iii) Sweep1 component a lot of times tells me that my computer has run out memory and that I should restart my PC. This is impossible to happen since I have much more RAM available that the amount that Rhino’s using (60GB compared to 5-6GB used from Rhino). Maybe I need to change some preferences? Not sure.

I attach a minimal version of my file. I also attach an image that shows the unaligned seam version with the ‘waters’ on the left and the aligned loft with the twists on the right. (249.6 KB) (258.9 KB)

Hi @HS_Kim !
A million thanks for your answer. I have been trying a lot of your previous answers in other posts which didn’t fully work for my case. Your answer is great!
I don’t fully understand everything in the script, so I will study it this afternoon, try more cases and will come back again until tomorrow!

Thanks a lot again!
Best regards!