balancing a tree works