added map-reduce function