generalize mapreduce (still need some tweaking ...)