The goal is to get the initial messy code into a state where you can easily add new features and write new tests. In other words, you refactor the code to make it more readable, robust, reusable, and maintainable. Refactoring should be an ongoing process of every developer over time. The goal of TDD should be to allow you to have a constant focus on writing production-quality code in the very first place. https://methodpoet.com/refactoring-in-tdd/