refactoring of the server code