refactor server exit