Improvements to error propagation of writeTo(), test improvements