Fixed possible bug with writeall