Refactored logic used to calculate group rules on demand