Refactor of api call