getMatch algorithm