new implementation of functions done (except I need to add singletons back into the type system)