Fixed some weird infinite loop bug