Refactor rest server