refactored granularity calculation to a helper