Fixed a bug in calibrate function