Merged recent changes from trunk. Fixes #8730.