Factor query and query_ into produceIO