bugfixing function substEnv