Moved several variables to more global scoping

Hopefully this alleviates the problems.  Cleaned up some.  Next step is
to post the blob in ajax to the db.