Bug fix for getNext
Added max and min using mapReduce