minor improvement on pattern matching