Use newer API functions to iterate and sort attributes. Closes #440
Typo