Fixed possible infinite loop error.