Yesterday a young man asked me what he could do about his inappropriate behaviour (I won't pass any remarks on what it was). Apart from telling him not to discuss such matters with a respectable woman, I told him that the Devil makes work for idle hands.
If you have too much time to think about things, the Devil will lead you astray. Go and help someone less fortunate than yourself - there's always someone out there who has less than you. Get and keep busy and soon you will find that your mind isn't turning to evil thoughts, you're too tired and get refreshing sleep instead of tossing and turning with bad dreams.