fixed the loop error