optimizing tsp code