Refactoring vs Rewrite: How to Choose Without Guesswork