Correct dataframe selection algorighm, DISTANCES WORK