Thanks Rob, that is helpful.
But the routines from the pearl script don't leave the variables in the right state to do the last part.

I'm trying to recreate it in a spreadsheet to see what values the variables should have at that point.
But finding time to look at it is difficult right now.

Just wanted to let you know I'm still working on it.