Port bugfixes from official repo