#43 changed group logic, accounted for repeated groups