> BTW, this code sorely needs tests, so when you find a bug (either in > the original code or in changes you introduced temporarily), if you > could add corresponding tests, that would be a great help. Hi Stefan, hi João, Thanks a lot. I managed to iron out the bugs in a way that I’m happy with. It seems to work well with everything I tested so far, and I went ahead and added some tests. Please have a look.