debugged the reference counting