added exit criteria for variance that returns NaN on an empty array