Refactor switch handling code

Now we have a generic, local function
to handle switch button states.

I didn't touch the switch handling logic itself yet.

Nice side effect: Code size is down by one kb.