Fix rebalance-related bugs