Refactored a socket close.