better pattern matching