Improve type encoder