Mapreduce bugfixes Backport

Backported bugfixes from #2552