Add PatternBuildAction + Minor improvements to pattern matching