Make sure subclasses are handled correctly.
Only loop over ancestors if necessary.