Endless loop fixed