consolidating grouping code
Merge pull request #460 from modilabs/group-str-458

consolidating grouping code