while loop was doing an early terminate by mistake