first cut at groups, and refactored a little