Refactoring, add process to recalculate jacobian only when necessary.