Sorting attrs & refs during serialization