Refactor rest api