The if statement in GetAncestor was quite hard to make sense of. Simplifying it improves readability and the added test ensures that the performance remains the same.
I’m not quite sure if the test makes sense to have but including it as it’s the code used to make sure no loss in performance was made. Tested locally up to height 1«29.