fix tree construction