Removed the nested RefCounters by introducing smart pointers.