Refactor of websocket host code.