Fix leak and test all mapreduce functions