refactoring to api