Refactored the socket client