Question about exact ODE. Why in $h'(y)$ contain $x$? Find the solution ODE
$$\left(x^3e^xy+4x^2e^xy+2xe^xy\right)dx+(x^3e^x+x^2e^x)dy=0.$$
Let $M(x,y)=x^3e^xy+4x^2e^xy+2y$ and $N(x,y)=x^3e^x+x^2e^x$.
\begin{align*}
 \dfrac{\partial M}{\partial y}&=\dfrac{\partial}{\partial y}\left(x^3e^xy+4x^2e^xy+2xe^xy\right) \\
 &=x^3e^x+4x^2e^x+2xe^x.\\
 \dfrac{\partial N}{\partial x}&=\dfrac{\partial}{\partial x}\left(x^3e^x+x^2e^x\right) \\
 &=3x^2e^x+x^3e^x+2xe^x+x^2e^x\\
 &=x^3e^x+4x^2e^x+2xe^x.
\end{align*}
This is exact ODE since $\dfrac{\partial M}{\partial y}= \dfrac{\partial N}{\partial x}$.
Now,
\begin{alignat}{2}
 &&\dfrac{\partial F(x,y)}{\partial x}&=M(x,y)\nonumber\\
 \Longleftrightarrow\quad
 &&\dfrac{\partial F(x,y)}{\partial x}&=x^3e^xy+4x^2e^xy+2y\nonumber\\
 \Longleftrightarrow\quad
 &&\int\partial F(x,y)&=\int\left(x^3e^xy+4x^2e^xy+2y\right) \partial x\nonumber\\
 \Longleftrightarrow\quad
 &&\int\partial F(x,y)&=\int x^3e^xy\partial x+\int4x^2e^xy \partial x+\int2y \partial x.\label{ijoet}
\end{alignat}
Consider that
\begin{align}
 \int x^3e^xy\partial x&=x^3e^xy-\int e^xy 3x^2 \partial x\nonumber\\
 &=x^3e^xy-\int 3x^2 e^x y \partial x\nonumber\\
 &=x^3e^xy-\left(3x^2e^x y-\int e^x y 6x \partial x\right)\nonumber\\
 &=x^3e^xy-3x^2e^x y+\int  6x e^x y\partial x\nonumber\\
 &=x^3e^xy-3x^2e^x y+6x e^x y-\int e^x y 6\partial x\nonumber\\
 &=x^3e^xy-3x^2e^x y+6x e^x y- 6 e^x y+h_1(y).\label{meong}
\end{align}
\begin{align}
 \int 4x^2e^xy\partial x&=4x^2e^xy-\int e^xy 8x \partial x\nonumber\\
 &=4x^2e^xy-\int 8x e^xy  \partial x\nonumber\\
 &=4x^2e^xy-\left(8x e^xy-\int e^xy 8 \partial x\right)\nonumber\\
 &=4x^2e^xy-8x e^xy+\int 8e^xy \partial x\nonumber\\
 &=4x^2e^xy-8x e^xy+ 8e^xy +h_2(y).\label{meong1}
\end{align}
\begin{align}
 \int2y \partial x&= 2xy+h_3(y).\label{meong2}
\end{align}
So, we have
\begin{alignat}{2}
 &&\int\partial F(x,y)&=x^3e^xy-3x^2e^x y+6x e^x y- 6 e^x y+h_1(y)\nonumber\\
 &&&\quad +4x^2e^xy-8x e^xy+ 8e^xy +h_2(y)+2xy+h_3(y)\nonumber\\
 \Longleftrightarrow\quad
 &&F(x,y)&=x^3e^xy+x^2e^x y-2 x e^x y+2e^x y+2xy +h(y)\nonumber
\end{alignat}
which $h(y)=h_1(y)+h_2(y)+h_3(y)$.
Next, consider that
\begin{alignat*}{2}
 &&\dfrac{\partial F(x,y)}{\partial y}&=N(x,y)\\
 \Longleftrightarrow\quad
 &&\dfrac{\partial}{\partial y}\left(x^3e^xy+x^2e^x y-2 x e^x y+2e^x y+2xy +h(y)\right)&=x^3e^x+x^2e^x\\
 \Longleftrightarrow\quad
 &&x^3e^x+x^2e^x -2 x e^x +2e^x +2x +h'(y)&=x^3e^x+x^2e^x\\
 \Longleftrightarrow\quad
 &&h'(y)&=2 x e^x -2e^x -2x \\
\end{alignat*}
When I want to find $h(y)$, I have found $h'(y)=2 x e^x -2e^x -2x$.
Why in $h'(y)$ contain $x$? What my mistake?
 A: You could group the terms of $M$ as you have seen in the $x$-derivative of $N$ as
$$
x^3e^xy+4x^2e^xy+2xe^xy=[x^3e^xy+3x^2e^xy]+[x^2e^xy+2xe^xy] 
\\
=(x^3e^xy)_x+(x^2e^xy)_x
$$
This gives the integral of $M$ in $x$-direction directly as
$$
\int M(x,y)dx =x^3e^xy+x^2e^xy+h(y).
$$
For some reason your partial integration resulted in extra terms.
A: It is much easier than what you make it to be: If
$$
M(x,y)\,\mathrm{d}x+N(x)\,\mathrm{d}y=0
$$
is exact and $M$ contains no terms independent of $y$, then LHS must be $\mathrm{d}(N(x)y)$, since that is what the product rule gives you for the $\mathrm{d}y$.  If there are terms independent of $y$ in $M(x,y)$, then you can (theoretically) integrate them to get $\mathrm{d}(N(x)y+f(x))$.
A: You wrote $M(x,y)=x^3e^xy+4x^2e^xy+2y$, but it should be $M(x,y)=x^3e^xy+4x^2e^xy+2\color{red}{xe^x}y.$ Then we have
$$\int2xe^xy\partial x=2xe^xy-2e^xy+h_3(y)$$
So we have
$$F(x,y)=x^3e^xy+x^2e^x y-2 x e^x y+2e^x y+\color{red}{2xe^{x}y-2e^xy }+h(y)$$
$$=x^3e^xy+x^2e^x y+h(y)$$
