Clean up and fix a bug in query plumbing
Clean up and fix a bug in query plumbing

aidancully/rust,aidancully/rust,graydon/rust,aidancully/rust,graydon/rust,graydon/rust,graydon/rust,graydon/rust,aidancully/rust,aidancully/rust,aidancully/rust,graydon/rust