Fixed mean/variance calculations to ignore NaN