fixed logic for optional fields