vertex detection bug fixed

Vertex may have not been found with some repetition of adding and deleting line.
the bug is fixed with small refactoring.