Refactoring of finite difference gradient computation

This refactoring makes it easier to implement one's own finite difference gradient/Jacobian policy.