faster matching algorithm