Only calculate type_num once