fixed not incrementing a while loop counter