Applied to the trunk (with a few tweaks).