Fix tree construction