Fixes bug#8730, bug#8781. Do not merge into trunk.