Whatsoever things are true, honest, just, pure, lovely and of good report think on these things. Since we strive to be virtuous and we praise the Lord for being a good and wonderful Father we should think on these things. And yes he will keep you in perfect peace if you can think about Him especially at the times when bad thoughts invade your mind. Use Him, think about the Lord, that's what he told us to do. Taste and see that the Lord is good,he will honor his Word.