Fix a refcounting bug
More debug info and fixes