refactoring of server code