Can now pass error and deriv functions to CG. I don't really like it though I'm gonna think of a cleaner way of doing it.