changed NewtonSolve, FormJf, and ComputeGain to accept Mode*