Fixed for loop issue