ensure array indexes are updated when sorting