first refactoring of server code
more server code refactoring