in reply to Suggestions for working with poor code
If necessary, the first thing I do when taking on bad code is reformat it. It doesn't matter whether it's Perl, Java, C, or HTML. A surprising number of problems (like mangled boolean conditions in branches and loops) fall right out when the code is tidied up so that you can actually see what it's doing.
Then it's a lot easier to get on with the fixes Ovid suggests.