Updated mesh generation logic