better matching algorithm