More transaction safety.

Is there any reason why this and the previous `if (err)` block can't be combined given they do exactly the same thing? maybe just `if (err) return writeDone(err);` earlier although maybe a different function name would be in order if you did that... `finish` maybe?