refactor API helper