moved pattern into its own function