Fix some bugs in calibrate/apply_model. Still not quite working.