From James Harvey (via a period of collaborative polishing), a patch