There comes a point where impossible to leave code in a better state without a major refactor.
The choice is between writing a few ugly if statements making the code a little worse or spending 10x the time refactoring hoping you don't introduce any regressions.