refactoring api calls