Refactoring the server code