improve type switch