Fixed bug in while loop