made the search function more effective
fixed a miscalculation in search giving bad distances