refactored switch statement into a simpler alternative