refactoring socket