Added additional check for socket