socket level changes for better error handling for preveting crashes