I think this will be more readable if you split the value calculation from the variance calculator.