Fixed bug that caused tree invariants to be violated