Fixed minor for loop bug