Using numerically stable algorithm for variance