Improve switch handling