Overhaul of the chi-squared gradient and Hessian functions.
The original functions have been renamed to dchi2_element and d2chi2_element as these calculate the
gradient for element j and the Hessian for element {j, k}. Two new functions, dchi2 and d2chi2 have
been written to calculate the full gradient and Hessian in one function call.
These changes will temporarily break a lot of code!