Rabbi Nachman teaches,
You cannot always prevent bad thoughts from entering your mind. However, you do have the power to reject them once you become aware of them. This is very important, because this is how you can make amends for sins you may have committed earlier on in your life. Perfect repentance has to balance the original sins exactly, and this is literally what happens here. Before, when you sinned, it was because the desire entered your mind and you succumbed to it. Now the same thought is in your mind , but this time you reject it.
Do not let yourself become discouraged if you constantly find all kinds of desires and fantasies pressing in on your mind. They actually provide you with the opportunity to repent and make amends for damage done in the past. Today you have the power to master your thoughts and temptations. When you do so, the sparks of holiness that fell because of your earlier transgressions are released and you can purify yourself. Your mind and your voice will be purified and you will find harmony and peace.
Likutey Moharan I, 27
With permission taken over from: Daily Dose Of Rabbi Nachman