fixed the location matching algorithm