DRYed out the api controller, experimented with the lib directory