BUG: Fix reference count issues