Tweaked the sampling code to take the number of reducers into account