The fix for #35 was messy, and this code in general is pretty gnarly. Here I have tried to streamline the logic and the processing, and ensure there is rich intermediate output for better debugging. Some bugs were being covered by redundant code paths, so streamlining surfaced them. I'm not sure if there are observable changes in the end, but I will tag anyway since there may be improvements in edge cases.
The fix for #35 was messy, and this code in general is pretty gnarly. Here I have tried to streamline the logic and the processing, and ensure there is rich intermediate output for better debugging. Some bugs were being covered by redundant code paths, so streamlining surfaced them. I'm not sure if there are observable changes in the end, but I will tag anyway since there may be improvements in edge cases.