some refactoring on switch state and deep linking