Fix bug in reference count.