added check for duplicate index pairs