Change algorithm to work for travelling salesmen problem