fixed for-loop error