This happens to me constantly. Here’s my definition:

To refractor code is to start out with the intention of merely refactoring it (such that it still works the same), but then you find that you can’t achieve your goals without changing the way it works, so you plow on ahead and do it anyway.