changed for loop to each loop