Fix logic for finding the best row