Fix some bugs in getNextNode()