Fixes to applying substitutin to TypeMap keys.