Refactoring into an API