bug fix for pattern matching