Fix WS add connection order and ensure (defer) to close the connection earlier