refactor: convert if...then...else to switch...case