Error handling when writing docx + error handling fixes at other places.