Major bug fixed and junctions detection

We are now using std::list to handle with junctions detection. A major
bug on the function IsBorder was also fixed.