Fixed differentiation.

Reimplemented differentiation for some basic functions.