How do we factor out $x^2 - x -2$ in this expression? Suppose we're given that
$$x^4 - 2x^3 +x-2$$
How do we factor out $x^2 - x -2$ in this expression?

$$(x^4 -x^3- 2x^2)-(x^3-x^2-2x)+(x^2-x-2) = x^2(x^2 -x-2)-x(x^2-x-2)+(x^2-x-2) = (x^2-x-2)(x^2-x+1)$$

This satisfies with what we want to get. However, I do not seem to have understood what is done there. Could I get your assistance in order to understand it? Perhaps there's better way of factoring. 
Regards

Another way: complete the square in  $\rm\color{#c00}{lead\ 2\ terms}$  yielding
$$ \underbrace{\color{#c00}{(x^2\!-\!x)^2} - (\color{#c00}{x^2}\!-\!x)-2}_{\Large \color{#c00}{x^4\ -\ 2x^3}\ +\ x\ -\ 2\!\!\!\!\!\!\!\!\!\!\!\! } = X^2\!-\!X\!-\!2 = (X\!+\!1)(X\!-\!2) = (x^2\!-\!x\!+\!1)\underbrace{(x^2\!-\!x\!-\!2)}_{\Large (x-2)(x+1)}$$
