Bugfixes and such for querying