Fix a leak where the "refcount" of a thing was always incremented even w...

...hen no wrapper was created around it

(also some assorted tiny changes)