Adding state saving/restoration