Changed to only add attributes that were set in the object; Skip setting defaults in the object, since these can be more clearly specified in the template
On second thought, preserving the order of the fields in the template is more useful than sorting them