fixed critical issues on tree building