fixed bug in writing file, file size not set correctly