completely refactored api_call