implement isInTree method