Update groupBy docs
Fix handling of duplicates and add tests