bugfixes to Query