added writer.sync() call.