Fix maybe-rebalance, add tests for AVL invariant