protected static function remove_duplicate_nodes($parent) {
        $length = count($parent->children);
        $index = 0;
        while ($index < $length) {
            $child = $parent->children[$index];
            if ($child->allow === $parent->allow) {
                // Remove child node, but add its children to this node instead.
                array_splice($parent->children, $index, 1);
                $length--;
                $index--;
                foreach ($child->children as $grandchild) {
                    $parent->children[] = $grandchild;
                    $length++;
                }
            } else {
                // Keep child node, but recurse to remove its unnecessary children.
                self::remove_duplicate_nodes($child);
            }
            $index++;
        }
    }