correcting the infinite loop error