matching algorithm implemented