implement query function