cleaned up code in calibrate.R