added optional grouping to SortReader/Writer