Added the function class and more or less fully implemented it.