Introduce a firstAncestorOfType method in Node
Also fix a whitespace issue
Use firstAncestorOfType instead of own looping