This piece of code is nasty for several reasons:
But maybe this is unavoidable for technical reasons here.