FIXED BUG: material is not written into the file stream.