added rebalancing logic