Multiple improvements and bugfixes to calibration