code optimization + tree-structure bug fix