These are some fixes I found while debugging something else. I'm far from sure about them, but it seems like something's wrong in this area of the code...
@gerddie, @lfrb: Thoughts?