Re-commit r34072 with some modifications: