The previous developer left a script that mostly works. Sometimes it double-counts, sometimes it stops, and nobody is sure why. I make it reliable without rewriting it: first the rules it must follow, written down with you; then tests for every rule, run against stand-ins of the systems it talks to, so your live data is never touched; then small fixes for every failing test, so you can read the diff and keep maintaining it yourself.