Refactor switch into if-else