Sorting metadata object list

When there are a bunch of objects in the list, it's easier if they're sorted alphabetically.

Also moved the logic into one function that's referenced by all three functions for DRY happyness.