switched from using for loop to each method