Various modifications, attempting to narrow down the for loop errors.