Improve type detection code.