Ah nice yes. Bit confused why Node.getAncestor mutates the node itself, but it seems like I can replace my function by getContaining, thanks, fixed!