Optimized error handling and added getMatchingRule().