Fixed for loop counter errors.