Sorting lists before comparing