fully implemented calibration routine