Refactor API functions