add tree traverse
refactor code for tree