adding more defensive code for socketry