refactor of apiService for clarity