use more general implementation of save/restore instance state