fixes to pattern matching and new utilities