Replace if statement with switch statement