public static Variable addOrUpdateVariable(final Variable newVariable, final List<Variable> targetVariables) {
		if (newVariable == null) {
			return null;
		}

		Variable theVariable = null;
		for (final Variable variable : targetVariables) {
			if (variable.getId().equals(newVariable.getId())) {
				if(newVariable.isOverwrite()) {
					if (AzotConfig.GLOBAL.DEBUG) {
						if(newVariable.getValue() != null && !newVariable.getValue().equals(variable.getValue())) {
							System.out.println("Updating variable: ${" + variable.getId() + "} = " + newVariable.getValue() + " (was '" + variable.getValue() + "')");	
						}
					}
					variable.setValue(newVariable.getValue());
				}
				theVariable = variable;
				break;
			}
		}

		if (theVariable == null) {			
			targetVariables.add(newVariable);
			theVariable = newVariable;
		}

		return theVariable;
	}