Refactor: breaking out api helper functions