When I catch my kids doing something undesirable, I usually sit them down and talk to them about it. I make sure to tell them why I think what they're doing is not right and how they could avoid or stop doing it again. I know it's tricky because kids are mature beyond their years, and mine, have minds of their own and could be very stubborn. There is no magic formula to curtailing a bad habit, really. It just takes practice (in talking and explaining to your kids well) and a lot of patience because more often than not, you have to remind them over and over again.
And oh, when I see my kids doing good, I praise them about it. The thing is, kids just need to be appreciated. They only do bad things to get your attention.