Ensure env values are truly immutable and add debug logging.

Fixes issue #1.