Refactor map reduce output