protected function buildTree($tree_data)
    {
        $parent_key = $this->config['parent'];
        $default_root_id = $this->config['default_root_id'];

        while (count($tree_data)) {
            $beginning_with = count($tree_data);

            foreach ($tree_data as $node_id => $node) {
                $node[$this->config['childs']] = [];
                $parent = (array_key_exists($parent_key, $node)) ? $node[$parent_key] : $default_root_id;
                if ($this->add($parent, $node[$this->config['id']], $node)) {
                    unset($tree_data[$node_id]);
                }
            }

            $this->ungracefulExit($beginning_with, $tree_data);
        }
    }