Index out of range

The sequence pairs, sometimes are copied and sometimes are empty in the swapping moves...