more socket refactoring