refactor functions to use a case statement