Improved write error message, fixed read_struct.