Attributes sort order fix

minor bug in how the next index number was being calculated