private function group_tags(array $tags){
    $res = [];
    if ( !empty($tags) ){
      foreach ( $tags as $i => $tag ){
        // Skip the 'memberof' tag
        if ( $tag['tag'] === 'memberof' ){
          continue;
        }
        $t = $tag['tag'];
        unset($tag['tag']);
        $res[$t][] = $tag['text'] ?? $tag;
      }
    }
    return array_map(function($r){
      if ( is_array($r) && (count($r) === 1) ){
        return $r[0];
      }
      return $r;
    }, $res);
  }