Modularize query definition