major pattern matcher improvements