simplify matching algorithm