When you factor out the expression $x^2+1$, you factor out the term having the smallest exponent (which you did), and then you subtract that exponent...
\$...\$ gives \textstyle, but ... produces \displaystyle. You can see the difference if you set the formula \lim_{x\to0}\frac{f(x)}{g(x)} in the two...