Added some reference counting stuff.