setup query function