I think you could simplify this using `os.environ.pop`, but it's not deeply important.