attemped fix for #39

This seams to be fixing #39.

It looks like you're required to increase the refcount of the resource every time you return it, instead of when you get and store it.

this is based on cac52a902bf3a727260455bdcdcf4915fb6c2f0c