Infinite loop fixed