fixed bug with for loop