Rewrite getNextNodeAfter() and add some assertions.