I used to have a big problem with having bad thoughts as I was going to sleep, which let to slip-ups many times. Recently I found something that really helps a lot - it's a bit of Bresslov mantra mediation. Just close your eyes and keep on repeating to yourself the words "Ribono Shel Olam." This really helped me - I hope it can help you too!