Adding recursive function to count nestedRules