Fix infinite loop bug.