refactored for loop to forEach method