finish map-with-reduce
refactored solution