<s>[INST] integration of a gaussian with $x^2$ I need to integrate
$$\int_{-\infty}^{\infty} x^2 e^{-ax^2} \qquad \text{where } a\in R$$
The book does the following:

I don't understand what's happening. I tried solving the integral using integration by parts and this is what I got
$$
\begin{align}
\int_{-\infty}^{\infty} x^2 e^{-ax^2} &= x^2\sqrt{\frac{\pi}{a}} - \int_{-\infty}^{\infty} \sqrt{\frac{\pi}{a}} 2x dx  && \text{as we are told } \int_{-\infty}^{\infty}dx e^{-ax^2}= \sqrt{\frac{\pi}{a}}\\
&=x^2\sqrt{\frac{\pi}{a}} - 2\sqrt{\frac{\pi}{a}}\frac{x^2}{2} && \text{as } \int xdx = \frac{x^2}{2} \\
&= 0
\end{align}
$$
What am I doing wrong?
Actually, I might have found a way of solving this
$$
\begin{align}
\int_{-\infty}^{\infty} x^2 e^{-ax^2} dx &= \int_{-\infty}^{\infty} x\cdot x e^{-ax^2} dx \\
&= - \frac{1}{2a} \int_{-\infty}^{\infty}  x(-2ax)e^{-ax^2} dx \\
&= -\frac{1}{2a}\left(\left[e^{-ax^2}\right]_{-\infty}^{\infty} - \int_{-\infty}^{\infty} e^{-ax2} dx\right) \\
&= -\frac{1}{2a}\left(0 - \sqrt{\frac{\pi}{a}}\right) \\
&= \frac{1}{2a}\sqrt{\frac{\pi}{a}}
\end{align}
$$
 [/INST] note that the derivative of $e^{-ax^2}$ is $-2ax e^{-ax^2}$, so
$$ x^2 e^{-ax^2} = \frac{-1}{2a}x \,(-2ax e^{-ax^2}) = \frac{-1}{2a}x\, \frac{d}{dx} e^{-ax^2}$$
Insert this into the integral and integrate by parts.
</s>