Refactoring patterns into sets