Yeah, that's one of the things I'm fixing now, making it as generic as possible in case of other corner cases I might have not foreseen.

Right now my approach is to figure out all gaps on the kv store, and for each gap copy them from the kvstore if available or rebuild them if not.