refactor switch case