added the balancing functionality