fixes bug of tree construction