There is a programming method where, after you finish coding and testing, you take the lessons and knowledge you've acquired and write it again from scratch. I haven't tried it yet, but it has its merits. If your testing was high-level and automated then it can enable "fearless refactoring".
RE: Burning the House for Better Nails : Rewriting @threespeak's backend again