refactored get_ids_and_row_mins to fix problem