Rewrite this to shift operations inside a managed container which
will be closed correctly upon exiting.