Bugfixes upstream

Some bugfixes for you.