map reduce implementation