modified for loop to use .each