corrected the for loop