Refactor: Extract 'closeSockets()'