Port over a whole bunch of earlier changes from 3.10 made by Arlen