break down inferType into several functions