Fix refcount bug in kernel creation.