diff --git a/include/grmGraph.h b/include/grmGraph.h
index 2f9734899b9722ba475baf36ad2ef06754424053..84b7c564780bc8044cd2f50a26565e1dfc992443 100644
--- a/include/grmGraph.h
+++ b/include/grmGraph.h
@@ -43,7 +43,7 @@ namespace grm
 		  Node is identified by the location
 		  of the first pixel of the region.
 		 */
-		long unsigned int m_Id;
+		std::size_t m_Id;
 
 		/*
 		  Bounding box of the region
@@ -77,7 +77,6 @@ namespace grm
 					return ptr;
 				}
 		};
-	
 
 	template<class DerivedNode>
 		struct Node : BaseNode
diff --git a/include/grmGraphOperations.txx b/include/grmGraphOperations.txx
index dcdbdc76e5d2b48331a3937dce0a9c6255a8047a..777ce6d7af6594b82950d7937196884d18db91d2 100644
--- a/include/grmGraphOperations.txx
+++ b/include/grmGraphOperations.txx
@@ -39,7 +39,7 @@ namespace grm
 	    {
 	    for(auto& r : seg.m_Graph.m_Nodes)
 	      {
-	      long int neighborhood[4];
+	      __int64 neighborhood[4];
 	      FOURNeighborhood(neighborhood, r->m_Id, width, height);
 	      for(short j = 0; j < 4; ++j)
 	        {
@@ -53,7 +53,7 @@ namespace grm
 	    {
 	    for(auto& r : seg.m_Graph.m_Nodes)
 	      {
-	      long int neighborhood[8];
+	      __int64 neighborhood[8];
 	      EIGHTNeighborhood(neighborhood, r->m_Id, width, height);
 	      bool haveNeighbors = false;
 	      for(short j = 0; j < 8; ++j)
@@ -79,7 +79,7 @@ namespace grm
 	void GraphOperations<TSegmenter>::UpdateMergingCosts(SegmenterType& seg)
 	{		
 		float min_cost;
-		long unsigned int min_id  = 0;
+		std::size_t min_id  = 0;
 		std::size_t idx, min_idx;
 
 		for(auto& r : seg.m_Graph.m_Nodes)
@@ -145,18 +145,21 @@ namespace grm
 	typename GraphOperations<TSegmenter>::NodePointerType
 	GraphOperations<TSegmenter>::CheckLMBF(NodePointerType a, float t)
 	{
-		if(a->m_Valid)
+		// TO FIX: if no-data are present within the image, an edgeless node is possible
+		// Here we check if the list of edges is empty prior to cost check.
+		// if(a->m_Valid)
+		if(a->m_Valid && a->m_Edges.size() > 0)
 		{
 			float cost = a->m_Edges.front().m_Cost;
 			
 			if(cost < t)
 			{
 				NodePointerType b = a->m_Edges.front().GetRegion();
-
+				
 				if( b->m_Valid)
 				{
 					NodePointerType best_b = b->m_Edges.front().GetRegion();
-
+					
 					if(a == best_b)
 					{
 						if(a->m_Id < b->m_Id)
@@ -174,7 +177,10 @@ namespace grm
 	typename GraphOperations<TSegmenter>::NodePointerType
 	GraphOperations<TSegmenter>::CheckBF(NodePointerType a, float t)
 	{
-		if(a->m_Valid)
+		// TO FIX: if no-data are present within the image, an edgeless node is possible
+		// Here we check if the list of edges is empty prior to cost check.
+		// if(a->m_Valid)
+		if(a->m_Valid && a->m_Edges.size() > 0)
 		{
 			float cost = a->m_Edges.front().m_Cost;
 
@@ -318,7 +324,7 @@ namespace grm
 
 		/* Update the costs of merging between adjacent nodes */
 		UpdateMergingCosts(seg);
-
+		
 		for(auto& region : seg.m_Graph.m_Nodes)
 		{
 		
@@ -412,7 +418,7 @@ namespace grm
 	{
 		bool merged = false;
 
-		std::vector<long unsigned int> randomIndices(seg.m_Graph.m_Nodes.size());
+		std::vector<std::size_t> randomIndices(seg.m_Graph.m_Nodes.size());
 		std::iota(randomIndices.begin(), randomIndices.end(), 0);
 		std::shuffle(randomIndices.begin(), randomIndices.end(), std::mt19937{std::random_device{}()});
 
diff --git a/include/grmNeighborhood.h b/include/grmNeighborhood.h
index c0b2090e299765f46d053637cc62cba76ae64f5c..bb6e58d5483b079d5ff55ae12c6c7cd4ea286257 100644
--- a/include/grmNeighborhood.h
+++ b/include/grmNeighborhood.h
@@ -18,17 +18,19 @@
 #ifndef GRM_NEIGHBORHOOD_H
 #define GRM_NEIGHBORHOOD_H
 
+#include <cstddef>
+
 enum CONNECTIVITY{FOUR = 0, EIGHT};
 
 namespace grm
 {
-	void FOURNeighborhood(long int * neighborhood,
-						  const long unsigned int id,
+	void FOURNeighborhood(__int64 * neighborhood,
+						  const std::size_t id,
 						  const unsigned int width,
 						  const unsigned int height);
 	
-	void EIGHTNeighborhood(long int * neighborhood,
-						   const long unsigned int id,
+	void EIGHTNeighborhood(__int64 * neighborhood,
+						   const std::size_t id,
 						  const unsigned int width,
 						  const unsigned int height);
 } // end of namespace grm
diff --git a/include/grmSegmenter.h b/include/grmSegmenter.h
index d0d23fc5d922511ef3a38af12d70e83bc89ea80f..d3d2bc3e31e5a5b21804ebd9479ee4c25ff898bd 100644
--- a/include/grmSegmenter.h
+++ b/include/grmSegmenter.h
@@ -129,7 +129,7 @@ namespace grm
           this->m_ImageHeight =this->m_InputImage->GetLargestPossibleRegion().GetSize()[1];
           this->m_NumberOfComponentsPerPixel = this->m_InputImage->GetNumberOfComponentsPerPixel();
 
-          const long unsigned int num_nodes = this->m_ImageWidth * this->m_ImageHeight;
+          const std::size_t num_nodes = this->m_ImageWidth * this->m_ImageHeight;
           this->m_Graph.m_Nodes.reserve(num_nodes);
 
           std::vector<bool> noDataFlags;
@@ -163,7 +163,6 @@ namespace grm
 
             this->m_Graph.m_Nodes.push_back(n);
             ++idx;
-
             }
         }
 
diff --git a/src/grmNeighborhood.cxx b/src/grmNeighborhood.cxx
index 6a6f262907ef022730666c74affefbb8b3056560..19e7593890cdee5dbb416d3303c3c6e69c21e55f 100644
--- a/src/grmNeighborhood.cxx
+++ b/src/grmNeighborhood.cxx
@@ -19,13 +19,13 @@
 
 namespace grm
 {
-	void FOURNeighborhood(long int * neighborhood,
-						  const long unsigned int id,
+	void FOURNeighborhood(__int64 * neighborhood,
+						  const std::size_t id,
 						  const unsigned int width,
 						  const unsigned int height)
 	{	
-		const unsigned int x = id % width;
-		const unsigned int y = id / width;
+		const std::size_t x = id % width;
+		const std::size_t y = id / width;
 
 		/* top */
 		neighborhood[0] = ( y > 0 ? (id - width) : -1 );
@@ -40,13 +40,13 @@ namespace grm
 		neighborhood[3] = ( x > 0 ? (id - 1) : -1 );
 	}
 	
-	void EIGHTNeighborhood(long int * neighborhood,
-						   const long unsigned int id,
+	void EIGHTNeighborhood(__int64 * neighborhood,
+						   const std::size_t id,
 						  const unsigned int width,
 						  const unsigned int height)
 	{
-		const unsigned int x = id % width;
-		const unsigned int y = id / width;
+		const std::size_t x = id % width;
+		const std::size_t y = id / width;
 
 		/* top */
 		neighborhood[0] = ( y > 0 ? (id - width) : -1 );