Fix bug where the last line ends up being repeated