Fix infinite loop bug (I hope)