factorisation code lecture + exception