Refactor REST api