refactoring functions internally to the api