Implementation of balance function.