I tend to tidy and reorganize as I read: Rename variables, extract intermediate values as named variables, group lines into stanzas, extract named functions, add missing doc comments, maybe add a few tests for something confusing or that I suspect to be broken…

That way, when I come back to it again, it’s a lot less work to follow. I only have to struggle once.