added match cache to avoid multiple matches for same pairs