Refactor the web api