move pattern matching definitions into methods