All these flags for stealing, allowing stealing, blah blah, are just ways to do some kind of dumb reference counting without actually have a reference count. When it gets super complex like this, maybe introducing a reference count is the way to go. It would be a bigger change, but perhaps more maintainable over time.