query bugfixes