Refactored API calls logic.