Fix rms calculation