update functions, some bugs in tree