Added some reference counting.