Fixed tree construction bugs