refactored api call