refactored rule
refactored expand-sets and extract-sets