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

$$\begin{align}
x^4-2x^3+x-2&= x^4 + (\color{red}{-2x^3+x-2})\\
&= x^4 + \color{red}{P(x)}\\
&= x^4 + \color{green}{-x^3-2x^2+}(\color{green}{x^3+2x^2}+\color{red}{P(x)})\\
&= \color{blue}{(x^4 + -x^3-2x^2)}+(x^3+2x^2+\color{red}{P(x)})\\
&= (x^2-x-2)(x^2)+(x^3+2x^2+\color{red}{P(x)})\\
&= (x^2-x-2)(x^2)+(x^3+2x^2+\color{red}{-2x^3+x-2})\\
&= (x^2-x-2)(x^2)+(-x^3+2x^2+x-2)\\
&= \dots\\
\end{align}$$
Try comparing the line with blue highlighting with your original problem (e.g. $x^4-x^3-2x^2$). Now, keep going, and try to split up the rest of the polynomial, using the same method.
