Reapply r250906 with many suggested updates from Rafael Espindola.