Refactors APIHandler:callAPI

Refactors and optimizes the APIHandler->callAPI.