Misc cleanup, mostly forward ported from uncommitted qtscript patches.