Misc changes forward ported from GLM patch.