Refactor api call