A couple of fixes. Commit msgs should explain.
ab2e02cc and 2e9ceda1 are only safety. Works without (afaik).
The others fix actual bugs.