Make next_result() check to see if we have any data available before trying to fetch it because it blocks for 1 second.  Change the order of keys we check to see if we are done so it will short-circuit faster.
Move the mapper and reducer loops into their own methods