Fix for loop error