Remove envlock, add env thread.
Merge remote-tracking branch 'upstream/master' into envlock