It helps to disassociate one's thoughts from compulsions, and ultimately to not act on those thoughts.This takes time, patience and discipline.That is why I sometimes regret that in the western culture why more effort is not expended in controlling one's own mind through prayer, meditation and other disciplines.