Refactor API integration