fix tree function