real query function, some other fixes