Fixed error in for loop