updated code with calibration working