Replaced each with map
Reduced amount of code