Fix refcount and itr problems

Also modified folding test that I am currently debugging: when adding
many items, eventually the fold starts missing some of them