Function Refactor

Refacotred the code to make it easier for plugins to use as well as
abstracting garbage collection. This should make it much easier to
develop extensions in the future.