Added gracePeriods to algorithm