ensure updating the height for both branches when rebalancing the tree after a node has been removed

and generalize the balancing logic to avoid repetitions