diff --git a/src/.deps/pdata-VCluster.Po b/src/.deps/pdata-VCluster.Po
index 0b7a89114d691c86732a60ffab0794e4a5452e1c..4de2a75bfeaff4058c22d98cee59d48326111c60 100644
--- a/src/.deps/pdata-VCluster.Po
+++ b/src/.deps/pdata-VCluster.Po
@@ -942,16 +942,18 @@ pdata-VCluster.o: ../../OpenFPM_vcluster/src/VCluster.cpp \
  ../../OpenFPM_data/src/memory.hpp ../../OpenFPM_data/src/config.h \
  ../../OpenFPM_data/src/memory.hpp ../../OpenFPM_data/src/meta_copy.hpp \
  ../../OpenFPM_data/src/Memleak_check.hpp \
- ../../OpenFPM_data/src/Grid/grid.hpp /usr/include/boost/shared_array.hpp \
+ ../../OpenFPM_data/src/for_each_ref.hpp \
+ ../../OpenFPM_data/src/Grid/grid_sm.hpp \
+ /usr/include/boost/shared_array.hpp \
  /usr/include/boost/smart_ptr/shared_array.hpp \
  ../../OpenFPM_data/src/Space/Shape/Box.hpp \
  ../../OpenFPM_data/src/Space/Shape/Sphere.hpp \
  ../../OpenFPM_data/src/base_type.hpp \
  ../../OpenFPM_data/src/Space/Shape/Point.hpp \
- ../../OpenFPM_data/src/Space/Shape/Point.hpp \
  ../../OpenFPM_data/src/Grid/grid_key.hpp \
  ../../OpenFPM_data/src/Grid/comb.hpp \
  ../../OpenFPM_data/src/Grid/grid_key_expression.hpp \
+ ../../OpenFPM_data/src/Space/Shape/Point.hpp \
  ../../OpenFPM_data/src/Grid/grid_key.hpp \
  ../../OpenFPM_data/src/Grid/Encap.hpp \
  ../../OpenFPM_data/src/memory_array.hpp \
@@ -3029,7 +3031,9 @@ config.h:
 
 ../../OpenFPM_data/src/Memleak_check.hpp:
 
-../../OpenFPM_data/src/Grid/grid.hpp:
+../../OpenFPM_data/src/for_each_ref.hpp:
+
+../../OpenFPM_data/src/Grid/grid_sm.hpp:
 
 /usr/include/boost/shared_array.hpp:
 
@@ -3043,14 +3047,14 @@ config.h:
 
 ../../OpenFPM_data/src/Space/Shape/Point.hpp:
 
-../../OpenFPM_data/src/Space/Shape/Point.hpp:
-
 ../../OpenFPM_data/src/Grid/grid_key.hpp:
 
 ../../OpenFPM_data/src/Grid/comb.hpp:
 
 ../../OpenFPM_data/src/Grid/grid_key_expression.hpp:
 
+../../OpenFPM_data/src/Space/Shape/Point.hpp:
+
 ../../OpenFPM_data/src/Grid/grid_key.hpp:
 
 ../../OpenFPM_data/src/Grid/Encap.hpp:
diff --git a/src/.deps/pdata-main.Po b/src/.deps/pdata-main.Po
index 2c985f560a77c072111128ece0c76e250458edea..a26f8d32f96a7468676b81c0088ced7937e77f15 100644
--- a/src/.deps/pdata-main.Po
+++ b/src/.deps/pdata-main.Po
@@ -907,16 +907,18 @@ pdata-main.o: main.cpp /usr/include/stdc-predef.h \
  /usr/include/c++/4.8.3/bits/stl_tree.h \
  /usr/include/c++/4.8.3/bits/stl_map.h \
  /usr/include/c++/4.8.3/bits/stl_multimap.h \
- ../../OpenFPM_data/src/Grid/grid.hpp /usr/include/boost/shared_array.hpp \
+ ../../OpenFPM_data/src/for_each_ref.hpp \
+ ../../OpenFPM_data/src/Grid/grid_sm.hpp \
+ /usr/include/boost/shared_array.hpp \
  /usr/include/boost/smart_ptr/shared_array.hpp \
  ../../OpenFPM_data/src/Space/Shape/Box.hpp \
  ../../OpenFPM_data/src/Space/Shape/Sphere.hpp \
  ../../OpenFPM_data/src/base_type.hpp \
  ../../OpenFPM_data/src/Space/Shape/Point.hpp \
- ../../OpenFPM_data/src/Space/Shape/Point.hpp \
  ../../OpenFPM_data/src/Grid/grid_key.hpp \
  ../../OpenFPM_data/src/Grid/comb.hpp \
  ../../OpenFPM_data/src/Grid/grid_key_expression.hpp \
+ ../../OpenFPM_data/src/Space/Shape/Point.hpp \
  ../../OpenFPM_data/src/Grid/grid_key.hpp \
  ../../OpenFPM_data/src/Grid/Encap.hpp \
  ../../OpenFPM_data/src/memory_array.hpp \
@@ -957,7 +959,7 @@ pdata-main.o: main.cpp /usr/include/stdc-predef.h \
  /home/i-bird/MPI/include/openmpi/ompi/mpi/cxx/file_inln.h \
  ../../OpenFPM_data/src/Vector/map_vector_std.hpp \
  ../../OpenFPM_data/src/Graph/map_graph.hpp \
- ../../OpenFPM_data/src/Grid/grid.hpp \
+ ../../OpenFPM_data/src/Grid/grid_sm.hpp \
  ../../OpenFPM_data/src/Space/Shape/HyperCube.hpp \
  ../../OpenFPM_data/src/mathutil.hpp \
  /usr/include/boost/test/included/unit_test.hpp \
@@ -3300,7 +3302,9 @@ config.h:
 
 /usr/include/c++/4.8.3/bits/stl_multimap.h:
 
-../../OpenFPM_data/src/Grid/grid.hpp:
+../../OpenFPM_data/src/for_each_ref.hpp:
+
+../../OpenFPM_data/src/Grid/grid_sm.hpp:
 
 /usr/include/boost/shared_array.hpp:
 
@@ -3314,14 +3318,14 @@ config.h:
 
 ../../OpenFPM_data/src/Space/Shape/Point.hpp:
 
-../../OpenFPM_data/src/Space/Shape/Point.hpp:
-
 ../../OpenFPM_data/src/Grid/grid_key.hpp:
 
 ../../OpenFPM_data/src/Grid/comb.hpp:
 
 ../../OpenFPM_data/src/Grid/grid_key_expression.hpp:
 
+../../OpenFPM_data/src/Space/Shape/Point.hpp:
+
 ../../OpenFPM_data/src/Grid/grid_key.hpp:
 
 ../../OpenFPM_data/src/Grid/Encap.hpp:
@@ -3404,7 +3408,7 @@ config.h:
 
 ../../OpenFPM_data/src/Graph/map_graph.hpp:
 
-../../OpenFPM_data/src/Grid/grid.hpp:
+../../OpenFPM_data/src/Grid/grid_sm.hpp:
 
 ../../OpenFPM_data/src/Space/Shape/HyperCube.hpp:
 
diff --git a/src/Decomposition/CartDecomposition.hpp b/src/Decomposition/CartDecomposition.hpp
index ced94e759ec428af0544a2544afa7a0af9570924..91c187d82b184ae0021fec176c65ef17a3533374 100644
--- a/src/Decomposition/CartDecomposition.hpp
+++ b/src/Decomposition/CartDecomposition.hpp
@@ -167,7 +167,7 @@ private:
 	{
 		// Create a grid where each point is a space
 
-		grid<3,void> g(div);
+		grid_sm<dim,void> g(div);
 
 		// create a grid_key_dx iterator
 
diff --git a/src/Decomposition/CartDecomposition_unit_test.hpp b/src/Decomposition/CartDecomposition_unit_test.hpp
index 226f526ac213df22d48c8c73a94d04f3b65b6af8..668adc11eb02970ad576a72d473e5614a1601805 100644
--- a/src/Decomposition/CartDecomposition_unit_test.hpp
+++ b/src/Decomposition/CartDecomposition_unit_test.hpp
@@ -29,7 +29,7 @@ BOOST_AUTO_TEST_CASE( CartDecomposition_test_use)
 
 	// Calculate the number of sub-domain on each dimension
 	for (int i = 0 ; i < 3 ; i++)
-	{div[i] = round_big_2(pow(n_sub,1.0/3));}
+	{div[i] = openfpm::math::round_big_2(pow(n_sub,1.0/3));}
 
 	// Decompose
 	dec.setParameters(div,box);
diff --git a/src/Decomposition/ORB.hpp b/src/Decomposition/ORB.hpp
index 7d40dfe534d8887f60a7475c8dd329b22419a21c..79c39307e42d18953985b86074a3cb837b8094fa 100644
--- a/src/Decomposition/ORB.hpp
+++ b/src/Decomposition/ORB.hpp
@@ -9,7 +9,7 @@
 #define ORB_HPP_
 
 #include "data_type/scalar.hpp"
-
+#include "mathutil.hpp"
 
 /*! \brief this class is a functor for "for_each" algorithm
  *
@@ -270,7 +270,7 @@ public:
 
 		dim_div = 0;
 
-		n_sub = round_big_2(n_sub);
+		n_sub = openfpm::math::round_big_2(n_sub);
 		size_t nsub = log2(n_sub);
 
 		// number of center or mass needed
diff --git a/src/Graph/CartesianGraphFactory.hpp b/src/Graph/CartesianGraphFactory.hpp
index 610c497614eadf068168cb99b72ceddf56b33cf3..f667d06aad14a68d5c3c276c073c7cabd82a5def 100644
--- a/src/Graph/CartesianGraphFactory.hpp
+++ b/src/Graph/CartesianGraphFactory.hpp
@@ -10,7 +10,7 @@
 
 #include "Vector/map_vector.hpp"
 #include "Graph/map_graph.hpp"
-#include "Grid/grid.hpp"
+#include "Grid/grid_sm.hpp"
 #include "Space/Shape/Box.hpp"
 #include "Space/Shape/HyperCube.hpp"
 
@@ -99,7 +99,7 @@ public:
 
 		// Construct a grid info
 
-		grid<dim,void> g(sz);
+		grid_sm<dim,void> g(sz);
 
 		// Create a graph with the number of vertices equal to the number of
 		// grid point
@@ -209,7 +209,7 @@ public:
 
 		// Construct a grid info
 
-		grid<dim,void> g(sz);
+		grid_sm<dim,void> g(sz);
 
 		// Create a graph with the number of vertices equal to the number of
 		// grid point
diff --git a/src/Grid/grid_dist_id.hpp b/src/Grid/grid_dist_id.hpp
index eb33fffedb1495ac46bd8046a2218b0e6da2bfd5..899a268e4c1c795ec866106263f3ea1f40e8f9b0 100644
--- a/src/Grid/grid_dist_id.hpp
+++ b/src/Grid/grid_dist_id.hpp
@@ -114,7 +114,7 @@ public:
 		// each dimension
 		size_t div[dim];
 		for (int i = 0 ; i < dim ; i++)
-		{div[i] = round_big_2(pow(n_sub,1.0/dim));}
+		{div[i] = openfpm::math::round_big_2(pow(n_sub,1.0/dim));}
 
 		// Create the sub-domains
 		dec.setParameters(div);
@@ -139,7 +139,7 @@ public:
 		// each dimension
 		size_t div[dim];
 		for (int i = 0 ; i < dim ; i++)
-		{div[i] = round_big_2(pow(n_sub,1.0/dim));}
+		{div[i] = openfpm::math::round_big_2(pow(n_sub,1.0/dim));}
 
 		// Box
 		Box<dim,size_t> b(g_sz);
diff --git a/src/Vector/vector_dist.hpp b/src/Vector/vector_dist.hpp
index e829f733ab919391822b9f3cbe919bde7eb68ba3..c68da5ab26981a37797a2c8947f41e2bd91a69f2 100644
--- a/src/Vector/vector_dist.hpp
+++ b/src/Vector/vector_dist.hpp
@@ -29,10 +29,10 @@ private:
 	//! Space Decomposition
 	Decomposition dec;
 
-	// Particle position vector for each subdomain the last one is the unassigned particles vector
+	// Particle position vector for each sub-domain the last one is the unassigned particles vector
 	Vcluster_object_array<openfpm::vector<point>> v_pos;
 
-	// Particle properties vector for each subdomain the last one is the unassigned particles vector
+	// Particle properties vector for each sub-domain the last one is the unassigned particles vector
 	Vcluster_object_array<openfpm::vector<prop>> v_prp;
 
 	// Virtual cluster
@@ -68,7 +68,7 @@ public:
 		// each dimension
 		size_t div[point::dims];
 		for (int i = 0 ; i < point::dims ; i++)
-		{div[i] = round_big_2(pow(n_sub,1.0/point::dims));}
+		{div[i] = openfpm::math::round_big_2(pow(n_sub,1.0/point::dims));}
 
 		// Create the sub-domains
 		dec.setParameters(div,box);
@@ -113,7 +113,7 @@ public:
 
 		auto it = v_pos.get(up_v).getIterator();
 
-		// Label all the particles it the processor id where they should go
+		// Label all the particles with the processor id where they should go
 		while (it.isNext())
 		{
 			auto key = it.get();
diff --git a/src/dec_optimizer.hpp b/src/dec_optimizer.hpp
index baf34e0b5d7e5ec53aa6aa89468be7c644f21d0d..ea7371baff9aa3b87404f63a06870fe814dd50a0 100644
--- a/src/dec_optimizer.hpp
+++ b/src/dec_optimizer.hpp
@@ -101,7 +101,7 @@ class dec_optimizer
 {
 	// create a grid header for helping
 
-	grid<dim,void> gh;
+	grid_sm<dim,void> gh;
 
 private:
 
diff --git a/src/pdata b/src/pdata
index 5b243341f6bca6893f937c36b081786128267c83..cd50ab8219083878b6f8ac263d174d518479482f 100755
Binary files a/src/pdata and b/src/pdata differ
diff --git a/src/pdata-HeapMemory.o b/src/pdata-HeapMemory.o
index e82ad42386b9a4fff7a8a1e8e7606e0492104205..4f8b9f0f284e1342ef713326eb61f7b20fe1673d 100644
Binary files a/src/pdata-HeapMemory.o and b/src/pdata-HeapMemory.o differ
diff --git a/src/pdata-VCluster.o b/src/pdata-VCluster.o
index 871a340059b570f877a4cd6438483240daf93c18..661ca37a97d0a609e1373161db93bb2740c3269a 100644
Binary files a/src/pdata-VCluster.o and b/src/pdata-VCluster.o differ
diff --git a/src/pdata-main.o b/src/pdata-main.o
index 4247308757311baa92f0f048de63cacbcda81b5b..c8440206ee929dba1afd5d1422f173c7ed2b3fc0 100644
Binary files a/src/pdata-main.o and b/src/pdata-main.o differ