Minor refactoring in query engine