fixes to pattern matcher