switch implementation
switch function