refactor Server and Client