cleanup query impl