Modify matching algorithm