Refactor 'remainingLines'