Save and restore state on pause and resume