refactored new line counting