Before refactoring legacy code, it is important to have a clear understanding of which parts of the code are the most critical and problematic. To do this, various tools and techniques can be used to analyze the code and pinpoint areas that need improvement. These include code metrics, which are quantitative measures of code quality such as complexity, cohesion, coupling, duplication, test coverage, etc. Code reviews are collaborative sessions where developers examine the code and provide feedback, suggestions and corrections. Additionally, code tests are automated or manual procedures that verify the functionality, reliability and performance of the code. After identifying which parts of the code need refactoring, they should be prioritized according to their impact, urgency and feasibility. A matrix or list can be used to rank refactoring targets based on their importance and difficulty.