Fix problem writing out meshes