refactored switch to be self contained