Also, you're in trouble if count == 1.  You need <code>
variance = --count ? M2 / count : 0;
</code> Ideally we'd also assert that, if count was 1, M2 is zero.