More elegant way to extract optional fields