Clean up code and debug calibration