refactor logic for function resetEnv & createEnvTmp