More fixes for arbitrary-length queries