Changed one small part about recognizing that socket was closed