maybe simpler to move this into the loop, instead of the hasWritten rigamarole?