Refactor api calls