Added more comments in main.  Moved saveNewState to a top level declaration.