Some refactoring around sockets