how does meditation work and can it stop bad thoughts?

how does meditation work and can it stop bad thoughts?