Fix incorrect indices after sorting character list.

Bug was introduced in 9460274ed9963b8a5df9c7626ecfff411790fc19