refactor switch stmt