working version to build a tree with binding type