added full reference counting to refs