code for switch enter/leave