Merge branch 'query-refactoring'