fixed bugs in refcount