Stable matching algorithm