Debugged for correct averaging of the measurment values.