you have to establish a cultural habit of tidying up a little when you're in there. often accompanied by a 'wow thats much better, thanks for doing that'.
more importantly you have to foster a sense of ownership. a common issue with the worst organizations I've worked with is fear and lack of understanding. the code isn't something we're shaping together - its just some large and awful monstrosity that bites you every time you get near it. every time you start pulling at a thread the whole thing unravels.
so you restrict your scope to as narrow a window as possible, and make the smallest changes you can to fix the bug or add the feature.
its the difference between living in a pleasant little village or a squalid favela.