fix the bug in isAncestor()