Refactor: better evaluation and differentiation.

Beginning of a refactor to handle functions that include variables.
Differentiation of these functions is also supported.