added protection against encoding errors in writing cp1255