Refactoring of numerical derivatives

The second order derivatives are still not working, which is why they
are commented out. I suppose this is to numerical rounding and
truncation issues.