appendEnv function complete