reconstruct and write to file