clean up query building