Refactor sockets