More refactoring for queryDB usage.