Refactor SocketHandler.