Fix "function too complex" ruff error
There are many functions that fail ruff because they are "too complex" (> 10 conditionals)
This is my attempt to "fix" those.
I'm not sure I feel good about this one. I don't have time to check whether I did everything correctly right now, I will do so tomorrow