Cleaned up some state storing and restoring.