Improved efficiency of typeOf(). For #37