Improved new line handling