Close websocket correctly