Time to time, I take all the thoughts wandering in my mind, analyse them, find out the source/causes of it. Then think about their positive & negative affects. Then consider their remedies or how they can be dispersed. Then move on with the lesson.
@Rilyn No, it work automatically by default now. The unnecessary thoughts are not processed and not stored in memory now. Now need not to even think about that. It becomes your nature after some time.