implementing pattern matching