fixed up writer to handle sparse files correctly