changed for to while loop

hopefully it will exit now!