refactored map method