fix some error handling and save tsp matrix in txt format too