Updated MatchesMask implementation.