Improved process_line