Due to circumstances I'm now working in a small software company. We make e-mail marketing management software and serve some big customers as our national railways and a big bank. The software has been developed about 6 years ago by two guys, one who left, the other now leading architect.
The problem starts with him. When he joined the company 6 years ago, this was his second job and he was a junior, but as everybody left due to a changing company directions, he in steps automatically got promoted into the role of lead. But he's not a good leader. In fact, he's not even a good programmer IMHO. E.g. he's often complaining about how we are using C#, while VB (often referring to VB6) is better. He's writing the coding guidelines, where he limits the use of many newer language features, as he doesn't understand them.
Over the years many people worked on the program, and it's now a 500000 line hot steaming mess of spaghetti. It has all the anti patterns you can imagine, like 5000+ line classes, 200+ character lines, no comments or documentation, no working tests (in intern wrote 80 application tests 4 years ago, but they were not maintained, so they're all broken).
I've learned to live with it (a bit... due to circumstances I don't have much choice), but many people don't. So we cannot keep new employees. They often leave within a year. They have a very hard time getting familiar with even the simplest code. And after that they just get frustrated after a while an go look for a more fun job. As you can imagine, a lot of the work is just bug hunting. Adding new features is not something anybody can do, as any change might break many things.
I've talked to a former long-time employee, and he says that the company is just locked in: this leading architect is the only one who really knows the software, so he gets freedom from the management. Management has tried stuff, but he gets agitated easily, so they just let him be most of the time.
Anyhow, that's the introduction. After I've been with the company for 1.5y, and me having 20+ years of programming experience, I've managed to convince the company (management and even the lead eng.) that this is a problem. And I'm now 'tolerated' to clean up the code. I'm started to writing (unit) tests. I'm breaking up the big classes into manageable chunks, etc, etc.
But this is the first time I'm doing this. I think 95-99% of the time this goes right, but every once in a while it doesn't, and some of my refactoring breaks something. This week even in production. Every time I had to have difficult conversations, and the lead eng. gets very frustrated and wants me to change everything back. As you can imagine, these conversations are demotivating for me. Also makes me want to leave.
How should I approach this? Are there best practices? Books? Ways to prevent errors?
edit: the dupe is not great. As it doesn't say how to do this in a hostile environment.... where every mistake leads to a problem. Why can I not see who closed the issue, like on SO?