Refactored map and reduce methods