Thanks! I posted in another thread with a link to my GitHub with the code, and adroitconceptions was able to help me solve the problem. (The logic of the loop was completely messed up.) There was a lot of extra stuff in there - manipulating the positioncount and so on - that was absolutely unnecessary.