fixing and refactoring the tree, more end2end testcases.