Fixed sum and average mapreduce function for issue #375