refactor tsp.py