No good deed goes unpunished, or so the saying goes. I've been wrestling with the computer version of this all afternoon. The corollary statement in programming land is, "add a feature, add a bug". The key to not entering this accursed place is to fully understand the original code and the ramifications of any changes. Things go much better when this is the case. The "bug" I've been fighting is from a sweeping change that I made with my fingers crossed and high hopes of nothing being broken. Well,95+% was not broken, but this is not enough to make those all so literal computers happy.
First, make a plan and think about the consequences of your changes. Make sure you understand how the code is supposed to work, how it actually works, and how it will work after you make the change. Remember that bugs are caused by not understanding the code. Make sure you understand the situation before you act. Changes to old code are far more likely to introduce new bugs than writing new code is, so think before you make matters worse.