improved function to find best points