Untangle logic writing optional fields to xml