Improved handling of newlines