added upstream's reference counting