code reorganization for the mesh building