added new line detection code