Fix segfaults and reading newlines