implemented directions and sorted by distance