Bugfixes

I think these are the only safe bugfixes to backport that don't change significant behavior.