Logic error in calibration