integrating recalibration with previous code