refactor solve_for_one_row