Added some code for mode debugging.
Still debugging.  Everything seems to work, except images are all crazy.