changed matching algorithm