Moved code from write to truncate