improve code for pattern matching