Improve auto switch logic