balancing a tree