fix bugs in env.
Merge branch '4.0'