Combine getBuckets and flattenLayers in cascade