refactor to use the API and not the http interface