reapply r64621 aka revert r64628, with various fixes: