Convert to chi-squared fitting algorithm