Save state periodically.