rename previousNodes to visitedNodes
fix bug where MIN_LENGTH_TO_KEEP isn't kept between iterations