It should be looping to keys.ordinality() rather than filerecnum - otherwise if the records are all the same size up to the split() and then differe after it will go wrong.