server refactor