fixed bug in pattern matching