# Problem with the sign of work

I have been stuck in a conceptual problem about the sign of the work. For example, suppose that we have a mass $$m$$ on a spring such that the equilibrium position is at $$x=0$$, and we stretch the spring to the position $$x_0$$. At the displacement $$x$$, the force on the mass is $$-kx\hat{i}$$ and the differential displacement is $$\vec{dx}=dx\hat{i}$$. So, the work done by the spring on the mass in this first situation is $$W_1=\int_{0}^{x_0}(-kx)\,dx=-\frac{kx_0^2}{2}$$Now, if we release the spring, it will oscillate around the position $$x=0$$. My doubt is the work in this situation, that is, the work done by the spring on the mass from the position $$x_0$$ to the position $$x=0$$. In this case, I believe that the force is still $$-kx\hat{i}$$ because the spring is still stretched . But, the differential displacement is now $$\vec{dx}=-dx\hat{i}$$. So, the work done by the spring on the mass from the point $$x_0$$ to the point $$x=0$$ is $$W_2=\int_{x_0}^{0}(-kx)\,(-dx)=-\frac{kx_0^2}{2}$$Although I think that's wrong, since I read in my textbook that the work in the second situation should be positive, I have not understood what I am doing wrong yet. Could you help me, please? In addition, sorry if my English may be broken, it's my second language and I am still working on it.

2. The order of integration limits $$W_2 = \int_{x_0}^0[...]$$ takes care of the direction of displacement. No need for an extra sign in front of $$dx$$. With this, $$W_1 = -W_2$$ as it should.