extracted the pattern matching into its own object