refactor switch cases