Thanks for the hint. I wanted to stay as close to the original code as possible, therefore the patch looks clumsy. The hplip code is ugly basically everywhere, I'd rather not start trying improve it. Just fix the obvious glitches.