changed while loop