The great scholar Ibn al-Qayyim wrote in his book al-Fawaa'id, under the chapter heading, "The Origin Of All Knowledge and Action" (p.224, Dar un-Nafaa'is 1989):
The origin of all perceived knowledge and chosen action lies in notions and thoughts. For these [both] necessitate imaginations, and imaginations call towards desires and desires necessitate the occurrence of action. The abundant repetition of this [action] then leads to the formation of a habit.
Thus, the rectification of all these [subsequent] steps lies in the rectification of the notions and thoughts, and the corruption [in these subsequent steps] lies in the corruption of these [notions and thoughts].
Rectification of thoughts occurs by their being mindful of their Master and Lord, and ascending to Him, revolving around His pleasure and love, for indeed, by Him, the Sublime, is all of rectification. He is the one with all guidance, and by His granting of success is all of right-direction, and in His guarding of His servant is every protection (for the servant) ...
He also said, continuing later:
Know that notions and whisperings lead what is associated with them to [the faculty] of thinking (thought). The thought then leads them to remembrance (tadhakkur). Thought takes them and leads them to the will (iraadah). The will takes them and leads them to the limbs and to action. These then become deeply rooted and become an [established] habit. Thus, to repel them (the notions and whisperings) from their very foundations is easier than cutting them off after their [development of] strength and completion.
He also said, a page later:
So when you repel the notion that comes to your [heart or mind], you will have repelled whatever follows on from it. And if you harbour it, it will become a roaming thought that will make use of the [individual's] desire. Then the desire and the thought together will both encourage the use of the limbs. If the limbs are not used, they (the desire and the thought) will return back to the heart with wishes and lusts to lead it in the desired direction.
It is known that rectifying the notions [that pass through the heart or mind] is easier than rectifying thoughts, and rectifying thoughts is easier than rectifying desires, and rectifying desires is easier than rectifying the corruption in action, and rectifying [the corruption in action] is easier than cutting off [from developed] habits.
Hence, the most beneficial cure is to busy yourself with thinking about what will benefit you as opposed to what will not benefit you, for thinking about what will not benefit you is the door to every evil.
What does this mean? Well, whatever thoughts, notions and ideas pass through your mind, then they will eventually lead to their expression in action. That eventual expression in action will be directly correlated to the nature of the original thoughts, notions and ideas. Good for good, evil for evil.
Further, to rectify at the very beginning of these steps - which is the stage where these thoughts and notions occur in your mind and heart - is much easier than having to get rid of a habit. Because a habit is the eventual outcome of all of these steps if a person allows them to continue progressively.
So a healthy sound mind is one in which only beneficial thoughts occur and all bad and evil thoughts are repelled. By keeping ones mind occupied with only those thoughts and ideas that are related to whatever is of outward benefit, a person keeps his or her actions in check.
A mind that has only good thoughts leads to good and beneficial actions. It is a healthy sound mind. Having bad thoughts and notions makes one susceptible to the outward expression of these thoughts in one's actions, leading to corrupt actions and development of hard-to-rid habits. It all starts with what goes through your heart and mind. Take care of it at that stage because its the easiest!
That's the simple message in these valuable words.