implements basic query function.