Integrate fixes from Prototype. Fixes #6285