Hand-apply 9d5f507fd0a65c8eb7b4fbcf971c9c859f3158a0 from master;
manual tweaks.