move mapreduce functions above