Consider the action of free Klein-Gordon theory
$S[\phi]=\frac{1}{2}\displaystyle\int d^4y(\partial_\mu\phi(y)\partial^\mu\phi(y)-m^2\phi^2(y))$
Integrating by parts in the first term gives me
$S[\phi]=-\frac{1}{2}\displaystyle\int d^4y(\phi(y)\partial_\mu\partial^\mu\phi(y)+m^2\phi^2(y))$
Now I take the functional derivative $\frac{\delta S[\phi]}{\delta\phi(x)}$ to get
$\frac{\delta S[\phi]}{\delta\phi(x)}=-\frac{1}{2}(\partial_\mu\partial^\mu\phi(x)+2m^2\phi(x))$
Setting this equal to zero should give me the Klein-Gordon equation, but the first term is off by a factor of 2. What's wrong with what I've done?
I know there are other ways to do this. I want to know what's wrong with this way.