refactored sendind and receiving from client to server