Fix getref and unref functions