cleaned up the calibration procedure into a new file called calibration_refactor.c