improve pattern matching