Manny's changes. Added permutation logic. Also added code to sum the distances.