Ugly merge from upstream master.