refactoring message server and client