fixed issues with reference counting and DELETEs