Backports stuff from master to 1.9

that should be all of master which is relevant for 1.9