Fix query factorization.