Swap if and case

Previously, there was an if containing a case. Now there is a case,
with the if inside each branch. This shouldn't change any behaviour, but
makes it easier to use a different if condition in some case branches
next.
udp