added a method to find an ancestor by type or by reference