rudimentary matching algorithm