switch logic