add the finish tree function