tree building correctly