Fix env conversion issues in env

@shykes is that what *you* had in mind ?

Fixes #3227
Fixes #2826

ping @tianon @unclejack