I was surprised by and love Paul Graham's comment on just this:
"Keep rewriting your program. Rewriting a program often yields a cleaner design. But it would have advantages even if it didn't: you have to understand a program completely to rewrite it, so there is no better way to get one loaded into your head."
Indeed! Even though I originally got that lesson from Martin Fowler (his absolutely legendary book "Refactoring"), I do see Paul Graham's article as an amazing source of this same wisdom as well.
"Keep rewriting your program. Rewriting a program often yields a cleaner design. But it would have advantages even if it didn't: you have to understand a program completely to rewrite it, so there is no better way to get one loaded into your head."
http://paulgraham.com/head.html