improving the rebalance code

@haio Making rebalance more efficient and more likely to succeed