Re-apply r97667 but with a little bit of thought put into the patch. This implements...