Fixed freezing due to infinite loop