refactor and add cn_nested_groups