Improved performance by doing fewer dict lookups

Now only a single dict lookup per type is needed, rather than 2.

(untested)