refactored the api call