Fix incorrect logic for extracting lines

Must have worked by pure luC