fixed a type error in for loop