refactoring my MapReduce algoritm