Fix buckets query