It's poor form to embed functions into switch statements. You should transform it into a private method.