Fixes #408

Includes the features mentioned in the comment for #408
The changes to DumpVariables weren't directly part of the change, but when I tried using DumpVariables to debug what I was doing it had some bugs and didn't dump properly.  I had to patch up DumpVariables to use it in my debugging.