The problem might not be in your switching code, but in the code handled after the change. I didn't see a problem in the code above.