Save state locally, fix a few bugs.