corrected for loop