implement pattern matching