Add function to match location pairs

plus some refactoring