Added function API, trying to granulate processes to make it easier to debug and expand upon