chg writeLeaves to use Seq.fold (with the incoming cursor wrapped as a seq)
keep firstLeaf in the LeafState so we don't have to seek through the entire list to find it afterward.