Simplified buckets code slightly