Fixed broken while loop