Pre-existing issue, but is 'groups' guaranteed to be non-empty here?