sockets refactoring