bug fix on for loop