Add working space conservation and restoration.

* work space is restored at the end of running.
* Wherever an exception happend, the work space is restored.
Merge branch 'stash-fix'