change to generatetree function