(maint) Cleanup of environment code after PUP-3341 fix

Just one commit, based on #3321.