Refactor the API