Fixed for loop errors