client: fix and handle new query and query cleanup