changed a while loop end condition