Refactor mapreduce and fix bug in keylist