patterns generation - refactored