address comments

fix code style and add docs and comments
use ExternalMerger for map-side aggregation
check memory usage during partitionBy()