fix reference count management