Basic matching algorithm working