Added sorting to resortIndex