Replaced for loop for for each