Refactor switch case statement