Updated code with RMS = sum sqrt((obs flux - avg flux)^2))