fix looping bug

This may fix the while loop bug.