Refactoring out API calls