AI: omit needless code, factor common code.