refactored the code that handles patterns into its own class