Fixed refcounting for references