move actual writing before so new size can be taken into account