Fixed a reference counting problem that caused seg fault.