Saving and restoring the context