Fixed crashing due to infinite loop