corrected best_ref function