Fixed a small bug - crashing after the socket is closed