prevent Id overflow in find_or_insert

this fixes #391