Minor nitpick regarding code-style:
```php
if ($group === null) {
    $group = '_NULL_';
}
```

Also, if the default group is `null`, it *should* come out as such (if at all possible). We also have to make sure to handle the case when a group with the literal name `_NULL_` does already exist. We should not merge them with the vertices with no group at all (`null`).