fixing bug in checkAncestor