fix for loop bug