Fixed while loop bug.