I've added comments to the context manager so that it's clearer what it's supposed to be doing.