Fix infinite while loop.