add some comments
calculate total distance