refactored isSubTree