refactored for loop to .each