Shift scanned_line validity check to function.