Fixing the variance calculation and adding some unit tests.