Added checks throughout the algorithm so that it does not crash. In addition, duplicate node removal modified so that the training image parsing/test image parsing is consistent when given the same set of images.