From my personal experience I found that if you feel too much guilt or get upset with your self for having a thought it will be harder to avoid...
You gotta realize that it's not your fault and you don't always have control over which thoughts come in...
Also if you try too hard to get rid of a thought it will not go away...
You have to just let it be, and try to get into other things; it will thus automatically be replaced...
There was someone who was obsessive about se'ual thoughts... When he asked R' Pinchos Sheinberg how to get rid of it, R' Sheinberg said the following:
"You know I also get thoughts that I don't like but what happens is that it comes in from one end of my head and floats out the other... But by you, you get so caught up with it that it can't float out...."
In a certain sense you have to be ok with the fact that the thought came in... Otherwise you"ll get too caught up with it...
The key is acceptance and distraction
Just one small guys thoughts on the matter...