refined the pattern matching