Refactoring out into an api package