Refactoring API interaction