Fixed most leaks after the refcounter change.