Mesh optimize length

Hey guys, I would like to optimize my mesh, because the lines at the lower parts of the geometry are quite different than the others. I tried it with this script but unfortunately it always says: Solution exception:Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection
What am I doing wrong? Or do you have better recomendations what I could do that?

Mesh optimize length.3dm (65.1 KB)

Optimize Mesh length.gh (18.4 KB)