fix bug where previous query-state leaked