Mapreduce bugfixes

Fixed multiple bugs inside the mapreduce framework. Unittests about to come, don't merge yet.