An HoH is one of those magical incantations I have not got the hang of yet. But after your suggesting I could just go through the log once, and use while loops in preference (I didn't know that a foreach grabs everything into memory), I managed to nut out a way of grabbing the right info at the right time (I've stuck my mucky code at the bottom of the thread).
Thanks very much for your input; it was a great help.