Updated autocalibration code