Refactored GetTreeItemType method