docs: public SDVariable updateVariableNameAndReference(SDVariable varToUpdate, String newVarName) {
          if (varToUpdate == null) {
              throw new NullPointerException("Null input: No variable found for updating!");
          }
  
          if(newVarName != null && variables.containsKey(newVarName) && varToUpdate != variables.get(newVarName).getVariable()){
              throw new IllegalStateException("Variable name \"" + newVarName + "\" already exists for a different SDVariable");
          }
  
          if (newVarName == null && variables.containsKey(varToUpdate.getVarName())) {
              //Edge case: suppose we do m1=sd.mean(in), m2=sd.mean(m1) -> both initially have the name
              // "mean" and consequently a new variable name needs to be generated
              newVarName = generateNewVarName(varToUpdate.getVarName(), 0);
          }
  
          if (newVarName == null || varToUpdate.getVarName().equals(newVarName)) {
              return varToUpdate;
          }
  
          val oldVarName = varToUpdate.getVarName();
          varToUpdate.setVarName(newVarName);
          updateVariableName(oldVarName, newVarName);
          return varToUpdate;
      }