Hi Tobias,
I am not completely happy about the introduction of yet another two global variables, but I also do not see an easy way out. Hence: OK.
Actually, I wasn't too happy myself, but, like you, I didn't find anything better.
I was playing around with the following test case – you might consider to add them as well. (I would exclude the error item, however.)
I have also added this as a test case. Committed as r280063 (without the spaces at the end of the lines that you pointed out in a separate mail). Thanks for the review! Regards Thomas