bug fix with for loop