Tweak Petri's changes to fold them into mainline.