Refactored the checks for socket sanity.