fix logic of tree structure