small bug fixes in querys