Formatting comments.
startNewIndex variable added to be more clear.
Attributes not in ordering are sorted and startNewIndex removed.