merge some useful work from an old branch
fix environ-var deletion loop