better balance algorithm