recursive pattern matching bug fix