Final stages of matching algorithm