split off query function