I've had good results when I followed these steps:
- Bring the code into a revision control system.
- Build test data and a test sytem so that proper
operation can be verified with an automated test.
- Create an independent test environment, do not
change production code.
- Fix the worst parts of the code, using test
data to make sure that the new system gets the same
results as the old system.
You will almost certainly find bugs and want to fix
them. Use a boss-approved release process and give
users warning that the system is changing.
Get users to test the improvements before release.
If you can't develop a realistic test system, you
will have to work much harder and develop many test
cases that verify that you aren't changing anything.
With this increase in level of difficulty, it might
not be justifiable to recode the system.
It should work perfectly the first time! - toma