Hello Peter,
I took another crack at this. Attached is a new patch that addresses the semantic comments from this and the other thread. It's all a bit tricky, comments welcome.
It seems that this patch does not apply anymore after Tom's 5815696. -- Fabien.