changed while loop behavior