Fix error in for loop