work on matching algorithm