MFA Auth Tree (Need help with Scripted Nodes)

I am currently developing an MFA tree with multiple Scripted Nodes.
The process unfolds as follows: Upon successful LDAP validation of the user, a Scripted Node checks if the user has MFA-Email Attribute Value or MFA-Mobile Number Attribute Value. If the user lacks both of these values, a Choice Node offers the user the option to select Register MFA via SMS, Email, or both. If the user opts for SMS, a Scripted Node prompts the user to input their mobile number, which is then saved as the MFA-Mobile Number using another Scripted Node. After MFA validation, if the Scripted Node confirms that the user has either MFA-Email or MFA-Mobile Number (indicating prior MFA registration), another Scripted Node identifies the present value and generates an OTP, sending it to the respective medium. The total number of scripted nodes involved in this process are as follows:

  1. Verify if the user has MFA-Email Attribute or MFA-Mobile Number Attribute values.
  2. Prompt the user to enter their mobile number.
  3. Save the mobile number as the MFA-Mobile Number Attribute value.
  4. Verify which value is present with the output as SMS, Email, or Both.

Is there any way we can simplify this ? and Please provide me help with Scripts for the nodes.