finally got calibration code working