Refactored to use .map instead of .each