refactored switch