fix gen_tree method