A couple of sharing bugfixes
Fix several bugs with reference counting when using execute() rather than analyse()