refactoring the server part