Change Compare function to use indices instead of values