When I was still new to programming I would always be excited about rewriting things from scratch. I'd scrap all the work I'd done on a half-complete project, starting again just so the code could be refactored to be slightly more elegant than before.
I only broke this habit after I read this article by Joel Spolsky on why rewriting from scratch is almost always a bad idea.
An existing codebase might be imperfect, use bad abstractions, and have clear opportunities for improvement. However it probably also encodes a ton of knowledge you can't grasp in one go – little details that you won't pick up on when you scan through the code; details that are critical to making the codebase actually work. When you start from scratch you inevitably miss those details in the beginning, and by the time you've added them back in the new code looks just as awful as the previous one.
So for the sake of your own sanity make incremental changes to codebases; improve them one file, module or abstraction at a time.