Refactoring
Code refactoring is a systematic process of improving code without creating new functionality in order to transform a mess into clean code and simple design.
Moreover, the Refactoring will teach you how to write a correct and clean code in the first place.
The best way to learn refactoring is to read this online book.