Added the build query function