some detector logic moved in determine_last_line_index