Fix prepare and commit_write to do the right thing