Made the code capable of minimizing chi2, kalman_chi2 and corrected_kalman_chi2