What is code refactoring?
It is improving the structure of code without changing its behaviour: splitting tangled modules, removing duplication, using clear names, adding checks. The user sees no difference, but further changes are made faster and with less risk. Before refactoring, the code's behaviour is captured in tests.
More in the guide to legacy system modernization.