modified gen_mesh