updated tree.cpp