Fixed possible infinite loop.