Factored out the reference counting code into W2_REFERENCE_COUNTER.