Fix infinite loop when skipping non-stylable ancestors
Also skip non-stylable ancestors before checking for a match
Simplify code for skipping non-stylable ancestors