Refactoring socket shutdown