Removed currentNode and stopFlag variables as they are no longer used.