Moves to using classes for management of function variables

Also adds a possibly useful new math function.