Fixed rms calculation with NaN's