Point errors when calling CreateLine

I have an array of points and I'm trying to loop through the array and create a line between each set of adjacent points.  I'm calling CreateLine in a loop and for some reason some of the XY points get mixed up when viewed in Solidworks.  For example, one point might have the Y-coordinate of the previous point.  I can't figure out why this would be happening.  I thought maybe I was looping too fast but I still get errors when putting a sleep command inside the loop.  Any help would be greatly appreciated.  Thanks.

SolidworksApi/macros