for loop bug