refactoring to API