Fixes reference counters