Fix writing out data