used write and flush instead of write everywhere