Refactor server code.