Add factory for creating sockets
Refactor sockets and corresponding tests