Improvements to the matching algo