Adding code to check ancestors