fixed EOL parsing (handles LF and CRLF), fixed error handling