Reapply the env-refactor changes from before the Lochemage merge.
Additional logging.
Auto-formatter.
JSLint corrections.